package com.totoro.tyrank.manager;

import com.totoro.tyrank.TyRank;
import com.totoro.tyrank.data.RankingData;
import com.totoro.tyrank.utils.ListUtil;
import com.totoro.tyrank.utils.RankingUtil;

import java.util.List;
import java.util.Map;

/**
 * @author Totoro
 * @version 0.1.0
 * @date 2025/8/1 - 19:37
 * @description
 **/
public class RankingReceiveManager {

    private final TyRank plugin;

    public RankingReceiveManager(TyRank plugin) {
        this.plugin = plugin;
    }

    /**
     * @author totoro
     * @description
     * @date  19:39
     * @param rankId, ranking
     * @return com.totoro.tyrank.data.RankingData.RankingReceive
     **/
    public RankingData.RankingReceive getReceive(String rankId, Integer ranking) {
        RankingData rankingData = RankingUtil.rankingIsAvailableNotEnd(rankId);
        if (null == rankingData) {
            return null;
        }
        // 获取领取预览，判断这个名次是否拥有领取预览
        Map<Integer, RankingData.RankingReceive> rankingReceiveMap = rankingData.getRankingReceiveMap();
        if (!rankingReceiveMap.containsKey(ranking)) {
            return null;
        }
        return rankingReceiveMap.get(ranking);
    }

    /**
     * @author totoro
     * @description
     * @date  19:38
     * @param rankId 排行榜Id, rankingText, ranking
     * @return com.totoro.tyrank.data.RankingData.RankingReceive
     **/
    public RankingData.RankingReceive getReceive(String rankId, String rankingText, Integer ranking) {
        RankingData rankingData = RankingUtil.rankingIsAvailableNotEnd(rankId);
        if(null == rankingData) {
            return null;
        }
        // 先判断这个名次是否存在rankingText里
        List<Integer> rankings = ListUtil.parseRange(rankingText);
        if(! rankings.contains(ranking)) {
            return null;
        }
        // 获取这个排行榜所有未处理的名次文本
        Map<String, Map<String, RankingData.RankingReceive>> allUntreatedRankingReceiveMap = TyRank.getRankingManager().getAllUntreatedRankingReceiveMap();
        if(! allUntreatedRankingReceiveMap.containsKey(rankId)) {
            return null;
        }
        Map<String, RankingData.RankingReceive> receiveMap = allUntreatedRankingReceiveMap.get(rankId);
        if(! receiveMap.containsKey(rankingText)) {
            return null;
        }
        return receiveMap.get(rankingText);
    }

    
}
